<template name="sendcar">
	<!-- 公共列表 -->
	<view class="mypage">
		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in orderList"
				:key="index" @click="openDetail(item)">
				<template v-for="(itemCC,indexCC) in menuConfig.list">

					<view class="flex-just-between bottom-border top-wrap" v-if="itemCC.Controls == 'ExBillno'  ">
						<text class="text-blue text-bold"> {{ item[itemCC.ID] || '-' }}</text>
						<view class="cu-capsule radius">
							<view class='cu-tag bg-blue sm'>
								<text class='cuIcon-medal'></text>
							</view>
							<view class="cu-tag line-brown sm">
								{{ index+1}}
							</view>
						</view>
					</view>
					<view class="card-list-row-1" v-else-if="itemCC.Controls == 'ExEnum'">
						<text class="cuIcon-title text-orange"></text>
						<text class="card-label ">{{ itemCC.Label }}:  </text>
						<text class="text-black">{{ resetExNum( item[itemCC.ID] , itemCC.Other)  }}</text>
					</view>
					<view class="card-list-row-1" v-else>
						<text class="cuIcon-title text-orange"></text>
						<text class="card-label ">{{ itemCC.Label }}:</text>
						<text class="text-black">{{ item[itemCC.ID] || '' }}</text>
					</view>
				</template>
				
				<template v-if="menuConfig.button.length">
					<view class="flex-just-between top-border margin-top btn-wrap">
						<button class="cu-btn round lines-blue"v-for="(itemB,indexB) in menuConfig.button" @click="handleBtn(item,itemB)">
							{{ itemB.name }}
						</button>
					</view>
				</template>
				
			</view>
		</view>
		<view class="next-btn-wrap " @click="nextTap">
			<button class="big-add bg-green shadow-blur">
				<text class="cuIcon-add text-bold"></text>
			</button>
		</view>
		
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'
	import AllConfig from '@/common/config.js'
	let _self, page = 1,
		total = 1,
		pageTitle, busType, requeryURL;
	let query = {
		// "StartTime": "2023-09-10 00:00:00.00",
		// "EndTime": "2029-10-10 23:59:59.999",
		"category": "BILLNO",
		"page": 1,
		"rows": 10,
		"sidx": "CREATIONTIME",
		"sord": "desc",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let bsTypeKey = {
		ware: 1,
		org: 3,
		company: 2
	}
	let queryJson = {};
	export default {
		computed: {
			...mapState(['userInfo']),
			// filterListCF() {
			// 	var t = AllConfig.App[this.listType].filter(item => {
			// 		return item.IsShow == 1;
			// 	})
			// 	return t;
			// },
		},
		data() {
			return {
				orderList: [],
				keyword: '',
				busType: 1,
				listType: '',
				menuConfig: null,
				menuCode:''
			};
		},
		onLoad(params) {
			_self = this
			console.log(params, AllConfig);
			page = 1;
			total = 1;
			queryJson = {}
			this.menuCode = params.type
			this.menuConfig = AllConfig.App[params.type]
			getApp().globalData.queryJsonLS = null
			if(this.menuCode=='menu1002'){
				queryJson.INSPCETYPE = 0
			}
			console.log(this.menuConfig);
			pageTitle =  this.menuConfig.title
			requeryURL = this.menuConfig.queryUrl
			this.getNewsList();
		},
		// 导航栏点击
		onNavigationBarButtonTap(e) {
			this.listenOnce()
			uni.navigateTo({
				url: './query?type=' + this.menuCode
			})
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			this.orderList = [];
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getNewsList();
		},
		methods: {
			...mapMutations(["setCheckData"]),
			handelSearch() {
				console.log(_self.keyword);
				queryJson.keyword = _self.keyword;
				page = 1;
				total = 1;
				this.orderList = [];
				this.getNewsList();
			},
			getNewsList() {
				if (page > total) {
					return uni.showToast({
						icon: 'none',
						title: '没有数据了。'
					})
				}
				query.page = page;
				query.queryJson = JSON.stringify(queryJson);
				this.axios({
					url: requeryURL,
					data: query,
					isLoading: 1
				}).then(res => {
					let {
						IsSuccess,
						Result,
						Message
					} = res;
					_self.setPageTitle(pageTitle + '(' + Result.records + ')')
					_self.orderList = [ ..._self.orderList,... Result.rows]
					total = Result.total
					page++
				})
			},
			
			// 初始监听
			listenOnce() {
				uni.$off('reload')
				uni.$once("reload", function(data) {
					queryJson= { ...queryJson , ...data }
					getApp().globalData.queryJsonLS = queryJson
					console.log( 'reload',  queryJson);
					_self.handelSearch()
				});
			},
			
			resetExNum(val,arr){
				try{
					let newArr = JSON.parse(arr)
					let getVal = newArr.filter(i=> i.id == val )
					return getVal.length ? getVal[0].name : ''
				}catch(e){
					//TODO handle the exception
				}
			},

			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},
			
			handleBtn(data,btn){
				let savedata = { BILLNO: data.BILLNO , ...btn.params }
				this.axios({
					url: btn.url ,
					data: savedata,
					isLoading: 1
				}).then(res => {
					this.$utils.tips('提交成功')
					this.handelSearch()
				})
			},

			openDetail(e) {
				if(this.menuCode == 'menu1002' ){
					if(e.BILLSTATUS !=5 ){
						return this.$utils.tips('该单据状态不可编辑')
					}
				}
				console.log(Path);
				uni.navigateTo({
					url: Path
				})
			},
			
			nextTap(){
				if(this.menuCode=='menu1002'){
					uni.navigateTo({
						url:'/pages/tab04/patrol/submit?title=物资临检&type=0' 
					})
				}else if(this.menuCode=='menu1001'){
					uni.navigateTo({
						url: './form?title=现场物资&type='+this.menuCode
					})
				}
			}



		}
	}
</script>

<style scoped lang="scss">

	
	.card-list-wrapper {
		width: 750upx;
		padding: 0 20rpx;
		margin: 10rpx auto;
		background-color: #f1f1f1;

		.count-list {
			padding: 20rpx 0;
			border-bottom: 1rpx solid #ddd;
		}
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.card-label {
		display: inline-block;
		width: 150upx;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}
</style>